package com.chookss.home.tuwen;

import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.chookss.R;
import com.chookss.Urls;
import com.chookss.tools.MyEvent;
import com.chookss.tools.MyToast;
import com.chookss.tools.Utils;
import com.chookss.tools.XJson;
import com.chookss.tools.okgoconfig.MyHttpRequest;
import com.chookss.tools.okgoconfig.callback.JsonCallback;
import com.lvgroup.hospital.base.BaseAct;
import com.lzy.okgo.model.Response;

import org.greenrobot.eventbus.EventBus;
import org.jetbrains.annotations.Nullable;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class TuwenTxtActivity extends BaseAct {

    @BindView(R.id.common_title_txt)
    TextView commonTitleTxt;
    @BindView(R.id.common_right_txt)
    TextView common_right_txt;
    @BindView(R.id.edContent)
    EditText edContent;
    private int maxSize = 500;//最大字数
    private String content;
    private int type = 0;//默认发布图文插入文本 1发布新闻转发链接的

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tuwen_txt);
        ButterKnife.bind(this);

    }

    @Override
    public void initData() {
        initState();
        commonTitleTxt.setText("文本");
        common_right_txt.setText("保存");
        common_right_txt.setVisibility(View.VISIBLE);
        content = getIntent().getStringExtra("content");
        if (!Utils.isNull(content)) {
            edContent.setText(content);
        }
        edContent.setMaxEms(500);
        edContent.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                if (s.toString().length() > maxSize - 1) {
                    MyToast.show("最多只能输入" + maxSize + "个字");
                }
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (edContent != null) {
            Utils.hideInputKeyboard(this, edContent);
        }
    }

    @OnClick({R.id.common_title_back, R.id.common_right_txt})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.common_title_back:
                finish();
                break;
            case R.id.common_right_txt:
                if (Utils.isNull(edContent.getText().toString())) {
                    MyToast.show("输入内容不能为空");
                    return;
                }
                Intent intent = new Intent();
                intent.putExtra("content", edContent.getText().toString());
                setResult(1001, intent);
                finish();
                break;
        }
    }
}
